﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace tp
{
    public partial class xiugai : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Userguanli"] != null)
            {
                this.txtname.Text = Session["Userguanli"].ToString();
            }
        }

        protected void ddlpro_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlpro.SelectedValue=="广东省")
            {
                ddlcity.Items.Clear();
                ddlcity.Items.Add("汕头市");
                ddlcity.Items.Add("梅州市");
            }
            else if (ddlpro.SelectedValue == "广西省")
            {
                ddlcity.Items.Clear();
                ddlcity.Items.Add("桂林市");
                ddlcity.Items.Add("柳州市");
            }
            else
            {
                ddlcity.Items.Clear();
            }
        }

        protected void ddlcity_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlcity.SelectedValue == "汕头市")
            {
                ddlcown.Items.Clear();
                ddlcown.Items.Add("潮阳区");
                ddlcown.Items.Add("潮南区");
            }
            else if (ddlcity.SelectedValue == "梅州市")
            {
                ddlcown.Items.Clear();
                ddlcown.Items.Add("梅江区");
                ddlcown.Items.Add("梅县区");
            }
            else if (ddlcity.SelectedValue == "桂林市")
            {
                ddlcown.Items.Clear();
                ddlcown.Items.Add("象山区");
                ddlcown.Items.Add("秀峰区");
            }
            else if (ddlcity.SelectedValue == "柳州市")
            {
                ddlcown.Items.Clear();
                ddlcown.Items.Add("柳南区");
                ddlcown.Items.Add("鱼峰区");
            }
            else
            {
                ddlcown.Items.Clear();
            }
        }

        protected void ibsure_Click(object sender, ImageClickEventArgs e)
        {
            string strCn = "Data Source=pc.hstc.cn;Initial Catalog=dhd2014112142;User ID=2014112142;Password=19961124";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                //string strbirth = "this.ddlyear.Text" + "this.ddlmonth.Text" + "this.ddlday.Text";
                //string straddr = "this.ddlpro.Text" + "this.ddlcity.Text" + "this.ddlcown.Text";
                cn.Open();
                //string strSql = "UPDATE Infomation SET No = '" + this.txtno.Text + "',Name = '" + this.txtname.Text + "',Age = '" + this.ddlage.Text + "',College = '" + this.ddlcoll.Text + "',Birth = '" + strbirth + "',Iden = '" + this.txtiden.Text + "',Addr = '" + straddr + "' WHERE(Name = '" + this.txtname.Text + "')";
                StringBuilder sb = new StringBuilder(1024);
                sb.Append("UPDATE  Infomation ");
                sb.Append("SET    No = @No, Name = @Name, College = @College, Birth = @Birth, Iden = @Iden, Addr = @Addr, Age = @Age ");
                sb.Append("WHERE   (Name = @Name) ");
                SqlCommand cmd = new SqlCommand(sb.ToString(), cn);
                SqlParameter pmsName = new SqlParameter("@Name", this.txtname.Text);
                SqlParameter pmsNo = new SqlParameter("@No", this.txtno.Text);
                SqlParameter pmsCollege = new SqlParameter("@College", this.ddlcoll.Text);
                SqlParameter pmsBirth = new SqlParameter("@Birth", this.ddlyear.Text + this.ddlmonth.Text + this.ddlday.Text);
                SqlParameter pmsIden = new SqlParameter("@Iden", this.txtiden.Text);
                SqlParameter pmsAddr = new SqlParameter("@Addr", this.ddlpro.Text+this.ddlcity.Text + this.ddlcown.Text);
                SqlParameter pmsAge = new SqlParameter("@Age", this.ddlage.Text);
                cmd.Parameters.Add(pmsName); 
                cmd.Parameters.Add(pmsNo);
                cmd.Parameters.Add(pmsCollege);
                cmd.Parameters.Add(pmsBirth);
                cmd.Parameters.Add(pmsIden);
                cmd.Parameters.Add(pmsAddr);
                cmd.Parameters.Add(pmsAge);
                int iUpda = cmd.ExecuteNonQuery();//insert,update,delete等都要使用ExecuteNonQuery
                if (iUpda < 1)
                {
                    lbl.Text="保存失败！";
                }
                else
                {
                    Response.Write("<script>alert('请点击再次确定！'); location.href = '/finally.aspx';</script>");
                }
            }
            catch (Exception ex)
            {
                this.lbl.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

       
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Request.QueryString["Theme"] != null)
            Page.Theme = Request.QueryString["Theme"].ToString();

        }
        protected void ibhuanfu_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("xiugai.aspx?Theme=" + ddlhuanfu.SelectedValue + "");
        }

        protected void ddlhuanfu_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
       
    }
}